﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Abarrotes_ABC
{
    class Conexion
    {
        public MySqlConnection Conector = new MySqlConnection("server = localhost; user id = root; password = software691; database = central_abastos");
        MySqlCommand cmd = new MySqlCommand();
        MySqlDataReader lector;

        public void abrir()
        {
            try
            {

                Conector.Open();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }

        public void cerrar()
        {

            Conector.Close();
        }

        public bool acceso(string cadena)
        {
            cmd = new MySqlCommand(cadena, Conector);//va a tener la consulta cadena del conector
            lector = cmd.ExecuteReader();//aqui se van agregar los datos

            if (lector.Read())//si leyo algo 
            {
                return true;
            }
            else//sino encontro nada
            {
                return false;
            }
        }

        public bool grabar(string cadena)
        {
            try
            {
                cmd = new MySqlCommand(cadena, Conector);
                cmd.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
